package com.fx.common.impl;

import com.fx.common.AbsButtonActionHandler;
import com.jfoenix.controls.JFXButton;
import javafx.event.ActionEvent;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JFXButtonActionHandler extends AbsButtonActionHandler<JFXButton, ActionEvent> {

    @Override
    public void setupButtonAction(JFXButton button) {
        button.setOnAction(this);
    }

    public void batchSetupButtonAction(List<JFXButton> buttons){
        if(CollectionUtils.isNotEmpty(buttons)){
            for(JFXButton b: buttons){
                setupButtonAction(b);
            }
        }
    }

    public void batchSetupButtonActions(JFXButton ... buttons){
        if(buttons != null && buttons.length > 0){
            for(JFXButton b: buttons){
                setupButtonAction(b);
            }
        }
    }

    public JFXButtonActionHandler bindAction(JFXButton button){
        setupButtonAction(button);
        return this;
    }
}
